<?php
namespace app\helpers;

/**
 * 通用函数封装
 */
class Common{

    /**
     * 毫秒时间戳 转化成整数,精确到毫秒
     */
    public static function microtime2String(){
        
        $t = microtime(true);
        list($usec, $sec)  = explode (' ', microtime()); 
        
        return '' . $sec . (int)($usec * 1000);
        
    }
    
    /**
     * 毫秒时间戳 转化成整数
     */
    public static function microtime2Time($time){
    
        $time = substr(''.$time, 0,10);
    
        return (int)($time);
    
    }
    
    /**
     * 计算密码
     * @param string $pwd : 密码
     * @param string $salt : 干扰串
     */
    public static function password($pwd,$salt){
        
        return md5(md5($pwd).$salt);
    }

    /**
     * base64加密 + 干扰串
     * @param $string
     */
    public static function encryptBase64Encode($string,$salt = ''){

        return base64_encode($salt.$string);
    }

    public static function encryptBase64Decode($string,$salt = ''){

        $_str = base64_decode($string);
        if($salt){
            $slth = strlen($salt);
            $lth = strlen($_str);
            $_str = substr($_str,$slth,$lth - $slth);
        }

        return $_str;
    }




}
